<?php
session_start();
include("../includes/conn.php");
$dbconn->admin_logincheck();
$adminid=$_SESSION['adminid'];
$id = isset($_GET['id'])?$_GET['id']:'';
$act = isset($_GET['act'])?$_GET['act']:'';
if($_GET['act']=='edit')
{
	$seluser=$dbconn->fetch($dbconn->query("select * from ".DBQIAN."user where id=$id"));
}
//编辑
if($_GET['act']=='add'){
	$name = isset($_POST['name'])?$_POST['name']:'';
	$tel=$_POST['tel'];
	$province = $_POST['province'];
	$city = $_POST['city'];
	$address = $_POST['address'];
	$car_type = $_POST['car_type'];
	$selrow = $dbconn->fetch($dbconn->query("select * from ".DBQIAN."user where id='$id'"));
	if ($selrow['id'])
	{
//		if (!$username)
//		{
//			echo"<script>alert('用户名不能为空');history.go(-1);</script>";exit;
//		}
		if (!$name)
		{
			echo"<script>alert('姓名不能为空');history.go(-1);</script>";exit;
		}
		if (!$tel)
		{
			echo"<script>alert('电话或手机号码不能为空');history.go(-1);</script>";exit;
		}
		if(!$province)
		{
			echo"<script>alert('请选择城市');history.go(-1);</script>";exit;
		}
		if(!$city)
		{
			echo"<script>alert('请选择城市');history.go(-1);</script>";exit;
		}
		if(!$address)
		{
			echo"<script>alert('请输入详细地址，这个是用来邮寄奖品的，请认真填写！');history.go(-1);</script>";exit;
		}
		if(!$car_type)
		{
			echo"<script>alert('请填写车型！');history.go(-1);</script>";exit;
		}
		$dbconn->noretquery("update ".DBQIAN."user set `name`='$name',`tel`='$tel',`province`='$province',`city`='$city',`address`='$address',`car_type`='$car_type' where id=".$id);
		//	echo 'insert into '.DBQIAN.'users(title,desc,time,content,url) values(\''.$title.'\',\''.$desc.'\',\''.$time.'\',\''.$content.'\',\''.$url.'\')';exit;
		//$dbconn->noretquery('INSERT INTO `'.DBQIAN.'users` (`id`,`username`, `name`, `password`, `sex`, `province`, `city`, `address`, `credit`, `last_login`, `createtime`, `openid`) values(null,\''.$username.'\',\''.$name.'\',\''.$password.'\',\''.$sex.'\',\''.$province.'\',\''.$city.'\',\''.$address.'\',0,\''.$login_time.'\',\''.$time.'\',\''.$openid.'\')');
		$dbconn->showalert("保存成功","userlist.php",1);
	}
	else 
	{
		$dbconn->showalert("不存在该用户，请换个手机号重新注册","userlist.php",1);
	}
}

;echo '<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8">
<title>欢迎登录后台管理系统</title>
<link href="css/base.css" rel="stylesheet" type="text/css" />
<link href="css/right.css" rel="stylesheet" type="text/css">
<script src="js/jquery.min.js"></script>
<!--<script src="js/jquery.js"></script>-->
<script language="javascript" type="text/javascript" src="../user/js/sel.js"   charset="gb2312"></script>
<script src="js/select-ui.min.js"></script>
<script type="text/javascript">
</script>
</head>
<body>
<div class="place"> <span>位置：</span>
  <ul class="placeul">
    <li><a href="index.php">首页</a></li>
    <li><a href="userlist.php">会员管理</a></li>
    <li>编辑</li>
  </ul>
</div>
<div class="formbody">
  <div class="formtitle"><span>会员管理编辑</span></div>
  <form name="radd" method="post" action="?act=add&id=';echo $seluser['id'];;echo '">
  <ul class="forminfo">
    <li>
      <label>姓名</label>
      <input style="color:red;" name="name" id="name" type="text" value="';echo $seluser['name'];;echo '" placeholder="用户名" class="dfinput" />
      <i></i>
    </li>
     <li>
      <label>防伪码</label>
      <input disabled="disabled" type="text" value="';echo $seluser['fwm'];;echo '" class="dfinput" />
    </li> 
    <li>
      <label>电话/手机</label>
      <input name="tel" id="tel" type="text" value="';echo $seluser['tel'];;echo '" class="dfinput" />
    </li>
    <li>
      <label>省份</label>
      <div style="border:1px;">
      	<select id="selProvince" name="province" onchange="provinceChange();"  style="width:347px; height:30px; font-size:14px;border:1px solid green; position:absolute; overflow:hidden"></select>
      	<script type="text/javascript">
		   $(function(){
		   		$("#selProvince").val("';echo $seluser['province'];;echo '");
		   		var $pro = $(\'#selProvince\');
				setCity($pro.val());
				$("#selCity").val("';echo trim($seluser['city']);;echo '");
				//alert("';echo trim($seluser['city']);;echo '");return false;
		   });
		</script>
      </div>
    </li>
    <li>
      <label>城市</label>
      <div style="border:1px;">
      <select id="selCity" name="city" style="width:347px; height:30px; font-size:14px;border:1px solid green; position:absolute; overflow:hidden"></select>
      </div>
    </li>
    <li>
      <label>详细地址</label>
      <textarea name="address" id="address" cols="55" rows="4" style="border:1px solid #000;">';echo $seluser['address'];;echo '</textarea>
    </li>
     <li>
      <label>车型</label>
      <input name="car_type"  type="text" value="';echo $seluser['car_type'];;echo '" class="dfinput" />
    </li>
    <li>
      <label>IP</label>
      <input disabled="disabled" name="ip" id="ip" type="text" value="';echo $seluser['ip'];;echo '" class="dfinput" />
    </li>
     <li>
      <label>时间</label>
      <input disabled="disabled" type="text" value="';echo $seluser['time'];;echo '" class="dfinput" />
    </li>
    <li>
      <label>是否中奖</label>
      <input disabled="disabled" type="text" value="';echo $seluser['praise'];;echo '" class="dfinput" />
    </li>
    <li>
      <label>&nbsp;</label>
      <input name="button" type="submit" class="btn" id="submit" value="确认保存"/>
    </li>
  </ul>
  </form>
</div>
<script type="text/javascript">
	$(function (){
		
	});
</script>
</body>
</html>'
?>